package com.labichaoka.chaoka.ui.home.fragment.my.feedback;

import com.labichaoka.chaoka.base.MyApplication;
import com.labichaoka.chaoka.entity.BaseResponse;
import com.labichaoka.chaoka.entity.FeedBackRequest;
import com.labichaoka.chaoka.net.BaseSubscriber;
import com.labichaoka.chaoka.net.DataManager;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import rx.subscriptions.CompositeSubscription;

/**
 * Created by ruan on 2018/8/9.
 */

public class FeedBackInteractorImpl implements FeedBackInteractor {
    private DataManager manager = new DataManager(MyApplication.mContext);
    private CompositeSubscription mCompositeSubscription = new CompositeSubscription();
    @Override
    public void commitFeedBack(FeedBackRequest request, OnFeedBackFinishedListener listener) {
        mCompositeSubscription.add(manager.commitFeedBack(request)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<BaseResponse>() {

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        listener.onFailed();
                    }

                    @Override
                    public void onNext(BaseResponse response) {
                        super.onNext(response);
                        listener.onSuccessed(response);
                    }
                })
        );

    }
}
